package com.servlet;

import com.bean.Student;
import com.dao.StudentDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UpdataServlet extends HttpServlet{
    public void doPost(HttpServletRequest request,HttpServletResponse response)
            throws ServletException,IOException{
        String id = request.getParameter("id");
        Student stu = StudentDao.searchStudent(id);
        if(stu!=null){
            stu.setName(request.getParameter("name"));
            stu.setSex(request.getParameter("sex"));
            stu.setDept(request.getParameter("dept"));
            stu.setPhone(request.getParameter("phone"));
            stu.setclassNum(request.getParameter("classNum"));
            stu.setAge(Integer.parseInt(request.getParameter("age")));
            StudentDao.updateStudent(stu);
        }else{
            RequestDispatcher view = request.getRequestDispatcher("/errorPage.jsp");
            view.forward(request, response);
        }
    }
}


